package programer.interviewer.link;

public class LinkUtil {

    public  static ListNode createLinkList(int[] arr) {
        ListNode head = new ListNode(-1);
        ListNode curNode = head;
        for (int i : arr) {
            ListNode node = new ListNode(i);
            curNode.next = node;
            curNode = curNode.next;
        }
        return head.next;
    }

    public static void printfLink(ListNode listNode) {
        StringBuilder stringBuilder = new StringBuilder();
        stringBuilder.append("[");
        while(listNode != null) {
            stringBuilder.append(listNode.val).append("->");
            listNode = listNode.next;
        }
        stringBuilder.replace(stringBuilder.lastIndexOf("->"),stringBuilder.length(), "");
        stringBuilder.append("]");
        System.out.println("print:" + stringBuilder.toString());
    }
}
